package com.common.model.result;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页实体类
 *
 * @author ccf
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = -275582248840137389L;
    /**
     * 总数
     */
    @ApiModelProperty(value = "总条数", dataType = "long")
    private Long count;
    /**
     * 是否成功：0 成功、1 失败
     */
    @ApiModelProperty(value = "状态", dataType = "int", example = "200")
    private int code;
    /**
     * 当前页结果集
     */
    @ApiModelProperty(value = "数据", dataType = "Object")
    private List<T> datas;


    @ApiModelProperty(value = "信息", dataType = "String", example = "操作成功")
    private String msg;


    public static PageResult empty(){
        PageResult result = new PageResult();
        result.setCount(0L);
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setDatas(new ArrayList());
        return result;
    }

    public static PageResult success(List datas, long count){
        PageResult result = new PageResult();
        result.setCount(count);
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setDatas(datas);
        return result;
    }
}
